package com.lc.afbx.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.lc.afbx.R;
import com.lc.afbx.adapters.DathAdater;
import com.lc.afbx.conn.PostApiCasualty;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2016/6/12.
 */
public class PolicyDetailsCasualtyActivity extends BaseActivity implements View.OnClickListener {

    private TextView policy_detail_casualty_state_tv;
    private TextView policy_detail_casualty_num_tv;
    private TextView policy_detail_casualty_time_tv;
    private TextView policy_detail_casualty_money_tv;
    private TextView policy_detail_casualty_shopName_tv;
    private TextView policy_detail_casualty_company_tv;
    private TextView policy_detail_casualty_insuranceName_tv;//保险名称
    private TextView policy_detail_casualty_phone_tv;
    private TextView policy_detail_casualty_idCard_tv;
    private TextView policy_detail_casualty_peopleName_tv;

    private TextView policy_detail_casualty_applicantName_tv;
    private TextView policy_detail_casualty_applicantIdCard_tv;
    private TextView policy_detail_casualty_applicantPhone_tv;
    private RelativeLayout policy_detail_casualty_applicant_info_rl;
    private RelativeLayout policy_detail_casualty_insuranced_info_rl;

    int i = 0;
    int j = 0;
    private ListView policy_detail_casualty_dath_lv;
    private ScrollView policy_detail_casualty_sv;
    //生存受益人信息
    private TextView policy_detail_casualty_lifeName_tv;
    private TextView policy_detail_casualty_beneficiary_tv;

    private DathAdater adapter1;
    private PostApiCasualty postApiCasualty = new PostApiCasualty(new AsyCallBack<PostApiCasualty.Info>() {

        @Override
        public void onSuccess(String toast, int type, PostApiCasualty.Info info) throws Exception {

            if (info.data.pstate.equals("2")) {

                policy_detail_casualty_state_tv.setText("已支付");

            } else {

                policy_detail_casualty_state_tv.setText("待支付");

            }

            policy_detail_casualty_num_tv.setText(info.data.ordersn);
            policy_detail_casualty_time_tv.setText(info.data.posttime);
            policy_detail_casualty_money_tv.setText("¥" + info.data.premium);
            policy_detail_casualty_shopName_tv.setText(info.data.store);
            policy_detail_casualty_company_tv.setText(info.data.insurance);
            policy_detail_casualty_insuranceName_tv.setText(info.data.insurance_type);

            //保险人信息
            policy_detail_casualty_applicantName_tv.setText(info.data.applicant.name);
            policy_detail_casualty_applicantIdCard_tv.setText(info.data.applicant.idnum);
            policy_detail_casualty_applicantPhone_tv.setText(info.data.applicant.cellphone);
            //被保险人信息
            policy_detail_casualty_phone_tv.setText(info.data.insurant.cellphone);
            policy_detail_casualty_idCard_tv.setText(info.data.insurant.idnum);
            policy_detail_casualty_peopleName_tv.setText(info.data.insurant.name);

            //生存受益人
            policy_detail_casualty_lifeName_tv.setText(info.data.lifeInfo.name);
//            //受益比率
//            percent.setText(info.data.lifeInfo.benefit_ratio + "%");
            // 死亡受益人
            policy_detail_casualty_dath_lv.setAdapter(adapter1 = new DathAdater(context, info.data.dathInfoList));

            policy_detail_casualty_sv.smoothScrollTo(0, 0);
        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }
    });


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_policy_detail_casualty);

        policy_detail_casualty_state_tv = ((TextView) findViewById(R.id.policy_detail_casualty_state_tv));
        policy_detail_casualty_num_tv = ((TextView) findViewById(R.id.policy_detail_casualty_num_tv));
        policy_detail_casualty_time_tv = ((TextView) findViewById(R.id.policy_detail_casualty_time_tv));
        policy_detail_casualty_money_tv = ((TextView) findViewById(R.id.policy_detail_casualty_money_tv));
        policy_detail_casualty_shopName_tv = ((TextView) findViewById(R.id.policy_detail_casualty_shopName_tv));
        policy_detail_casualty_company_tv = ((TextView) findViewById(R.id.policy_detail_casualty_company_tv));
        policy_detail_casualty_insuranceName_tv = ((TextView) findViewById(R.id.policy_detail_casualty_insuranceName_tv));

        //被保人信息
        policy_detail_casualty_phone_tv = ((TextView) findViewById(R.id.policy_detail_casualty_phone_tv));
        policy_detail_casualty_idCard_tv = ((TextView) findViewById(R.id.policy_detail_casualty_idCard_tv));
        policy_detail_casualty_peopleName_tv = ((TextView) findViewById(R.id.policy_detail_casualty_peopleName_tv));

        //投保人信息
        policy_detail_casualty_applicantName_tv = ((TextView) findViewById(R.id.policy_detail_casualty_applicantName_tv));
        policy_detail_casualty_applicantIdCard_tv = ((TextView) findViewById(R.id.policy_detail_casualty_applicantIdCard_tv));
        policy_detail_casualty_applicantPhone_tv = ((TextView) findViewById(R.id.policy_detail_casualty_applicantPhone_tv));

        //投保人信息,被保险人信息 布局
        policy_detail_casualty_applicant_info_rl = ((RelativeLayout) findViewById(R.id.policy_detail_casualty_applicant_info_rl));
        policy_detail_casualty_insuranced_info_rl = ((RelativeLayout) findViewById(R.id.policy_detail_casualty_insuranced_info_rl));

        //投保人信息,被保险人信息 布局 上面那一条
        findViewById(R.id.policy_detail_casualty_applicant_rl).setOnClickListener(this);
        findViewById(R.id.policy_detail_casualty_insuranced_rl).setOnClickListener(this);

        //生存受益人信息
        policy_detail_casualty_lifeName_tv = ((TextView) findViewById(R.id.policy_detail_casualty_lifeName_tv));
        //收益比例
        policy_detail_casualty_beneficiary_tv = ((TextView) findViewById(R.id.policy_detail_casualty_beneficiary_tv));

        policy_detail_casualty_dath_lv = ((ListView) findViewById(R.id.policy_detail_casualty_dath_lv));

        policy_detail_casualty_sv = ((ScrollView) findViewById(R.id.policy_detail_casualty_sv));


        postApiCasualty.id = getIntent().getStringExtra("id");
        postApiCasualty.type = getIntent().getStringExtra("type");
        postApiCasualty.execute(context);
    }

    @Override
    public void onClick(View view) {


        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.policy_detail_casualty_applicant_rl:

                if (i++ % 2 == 0) {

                    findViewById(R.id.img2).setVisibility(View.VISIBLE);
                    findViewById(R.id.img1).setVisibility(View.GONE);
                    policy_detail_casualty_applicant_info_rl.setVisibility(View.GONE);

                } else {
                    findViewById(R.id.img2).setVisibility(View.GONE);
                    findViewById(R.id.img1).setVisibility(View.VISIBLE);
                    policy_detail_casualty_applicant_info_rl.setVisibility(View.VISIBLE);

                }

                return;

            case R.id.policy_detail_casualty_insuranced_rl:

                if (j++ % 2 == 0) {

                    findViewById(R.id.img4).setVisibility(View.VISIBLE);
                    findViewById(R.id.img3).setVisibility(View.GONE);
                    policy_detail_casualty_insuranced_info_rl.setVisibility(View.GONE);

                } else {
                    findViewById(R.id.img4).setVisibility(View.GONE);
                    findViewById(R.id.img3).setVisibility(View.VISIBLE);
                    policy_detail_casualty_insuranced_info_rl.setVisibility(View.VISIBLE);

                }

                return;


        }


    }

}
